package com.dev.security.controller;

import com.dev.security.service.OrgService;
import com.dev.security.service.RoleService;
import com.dev.security.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 机构控制器
 *
 * @author yuboon
 * @version v1.0
 * @date 2020/04/04
 */
@RestController
@RequestMapping("/org")
public class OrgController {

    @Autowired
    private OrgService orgService;

    @PostMapping("/save")
    public ResponseEntity save(OrgVo orgVo){
        return ResponseEntity.ok(orgService.save(orgVo));
    }

    @PostMapping("/update")
    public ResponseEntity update(OrgVo orgVo){
        return ResponseEntity.ok(orgService.update(orgVo));
    }

    @PostMapping("/remove")
    public ResponseEntity remove(int id){
        return ResponseEntity.ok(orgService.remove(id));
    }

    @PostMapping("/batchRemove")
    public ResponseEntity batchRemove(String ids){
        return ResponseEntity.ok(orgService.batchRemove(ids));
    }

    @GetMapping("/list")
    public ResponseEntity list(OrgVo orgVo, PageVo pageVo){
        ResponseData<List<OrgVo>> result = new ResponseData();
        PageVo<OrgVo> pageVo1 = orgService.selectList(orgVo,pageVo);
        result.setCount(pageVo1.getTotal());
        result.setData(pageVo1.getList());
        return ResponseEntity.ok(result);
    }

    @GetMapping("/tree")
    public ResponseEntity tree(){
        List<TreeVo> treeVoList = orgService.selectTree();
        return ResponseEntity.ok(treeVoList);
    }

}
